package com.wuyoucar.service.impl;

import com.wuyoucar.common.ResultBean;
import com.wuyoucar.entity.TReport;
import com.wuyoucar.entity.TUser;
import com.wuyoucar.mapper.TReportMapper;
import com.wuyoucar.service.InTReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Author: jiangdz
 * @ProjectName: mywuyou_car
 * @Package: com.wuyoucar.service.imp
 * @ClassName: TReportServiceImpl
 * @Description:
 * @Date: 2020-09-27  17:31
 * @UpdateUser: asus
 * @UpdateDate: 2020-09-27  17:31
 * @UpdateRemark: [说明本次修改内容]
 * @Version: [v1.0]
 * @Since JDK 1.8
 */
@Service
public class TReportServiceImpl implements InTReportService {
    @Autowired
    private TReportMapper tReportMapper;

    @Override
    public ResultBean addReport(String  imgPath, Date risktime, Date reporttime,
                                Integer policynum,Integer userid,String reportertel) {
        ResultBean resultBean = new ResultBean();
        TReport tReport = new TReport();
        tReport.setReportimages(imgPath);
        tReport.setRisktime(risktime);
        tReport.setReporttime(reporttime);
        tReport.setPolicynum(policynum);
        tReport.setReportstate("待处理");
        tReport.setPayprogram(1);
        TUser user = new TUser();
        user.setUserid(userid);
        tReport.settUser(user);
        tReport.setReportertel(reportertel);
        int n= tReportMapper.addReport(tReport);
        if (n > 0) {
            resultBean.setCode(0);
            resultBean.setMsg("申请成功，请等待处理！");
        } else {
            resultBean.setCode(-1);
            resultBean.setMsg("申请失败！");
        }
        return resultBean;
    }

    @Override
    public ResultBean selectAll(Integer userid) {
        List<TReport> tReports = tReportMapper.selectAll(userid);
        if (tReports.size()==0){
           return new ResultBean(404,"您的爱车没有出过任何事故哦");
        }else{
           return new ResultBean(200,"查询成功",tReports);
        }
    }
}
